#include "SSAOBlurFX.h"

SSAOBlurFX::SSAOBlurFX(ID3D11Device* device)
	: AbstractFX(device, L"FX/SSAOBlur.fxo")
{
	InitInputLayout(device);
	InitShaderVariablePointers();
};

SSAOBlurFX::~SSAOBlurFX()
{}

void SSAOBlurFX::InitInputLayout(ID3D11Device* device)
{
	D3D11_INPUT_ELEMENT_DESC inputLayout[] = 
	{
		{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,  D3D11_INPUT_PER_VERTEX_DATA, 0},
		{"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT,    0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0}
	};

	CreateInputLayout(device, inputLayout, 2);
}

void SSAOBlurFX::InitShaderVariablePointers()
{
	texelWidthVar = effect->GetVariableByName("texelWidth")->AsScalar();
	texelHeightVar = effect->GetVariableByName("texelHeight")->AsScalar();

	inputTexVar = effect->GetVariableByName("inputTexture")->AsShaderResource();
	viewSpaceNormalDepthVar = effect->GetVariableByName("viewSpaceNormalDepthMap")->AsShaderResource();
}

void SSAOBlurFX::SetShaderResources(ID3D11ShaderResourceView* input,
	ID3D11ShaderResourceView* viewSpaceNormalDepthMap)
{
	inputTexVar->SetResource(input);
	viewSpaceNormalDepthVar->SetResource(viewSpaceNormalDepthMap);
}

void SSAOBlurFX::SetCBufferTexelData(float width, float height)
{
	texelWidthVar->SetFloat(width);
	texelHeightVar->SetFloat(height);
}